app.controller("routcomment", ["$scope", "$timeout", "$rootScope", "$stateParams", "$state", "$http", function($scope, $timeout, $rootScope, $stateParams, $state, $http) {
	$rootScope.page.showfooter = true;
	$rootScope.page.footer = 'mine';
	$http({
			method: 'post',
			url: '' + $rootScope.Location + 'Comment/go_comment',
			headers: {
				'Content-Type': 'application/x-www-form-urlencoded'
			},
			data: {
				user_Id: localStorage.getItem("user_ID"),
				token: localStorage.getItem("token"),
				order_Id: $stateParams.Id,
				road_Id: $stateParams.id
			}
		}).success(function(data) {
			console.log(data)
			$scope.title = data["list"]["title"]
			$scope.Imgs = data["list"]["images"]
		})
		//星星
	var oStar = document.querySelectorAll(".star")[0];
	var aLi = oStar.getElementsByTagName("li");
	var oUl = oStar.getElementsByTagName("ul")[0];
	//	var fenshu = document.getElementById("fenshu");
	var star = []
	for(i = 1; i <= aLi.length; i++) {
		aLi[i - 1].index = i;
		//鼠标移过显示分数
		aLi[i - 1].onmouseover = function() {
			fnPoint(this.index);
		};
		//点击后进行评分处理
		aLi[i - 1].onclick = function() {
			iStar = this.index;
			star.push(iStar)
		}
	}
	//评分处理
	function fnPoint(iArg) {
		//分数赋值
		iScore = iArg || iStar;
		for(i = 0; i < aLi.length; i++) aLi[i].className = i < iScore ? "on" : "";
	}
//	document.addEventListener("plusready", onPlusReady, false)
//
//	function onPlusReady() {
//
//	}
//	var iFilename = "_doc/camera/";
//	var lfs = null;
//
//	function chooseImg() {
//		var Li = ""
//		var Url = [];
//		plus.gallery.pick(
//			function(e) {
//				for(var i in e.files) {
//					Li += "<li><img src='" + e.files[i] + "'/></li>"
//					lfs = e.files;
//					Url.push(e.files[i])
//					zipImg(e.files[i], 20)
//				}
//				$(".ul_img").html(Li)
//				localStorage.setItem("urlImg", Url)
//			},
//			function(e) {
//				alert("取消选择图片")
//			}, {
//				filter: "image",
//				multiple: true,
//				maximum: 3,
//				system: false,
//				filename: iFilename,
//				selected: lfs,
//				onmaxed: function() {
//					plus.nativeUI.alert('最多只能选择3张图片');
//				}
//			}
//			//filter:相册中可选文件过滤器
//			//multiple:是否支持多选图片
//		)
//	}
//
//	function zipImg(imgFile, quality) {
//		var fild = []
//		plus.zip.compressImage({
//				src: imgFile, //原始路径
//				dst: imgFile, //压缩后的路径
//				quality: quality, //图片质量
//				overwrite: true //是否替换
//			},
//			function(e) {
//				//					uploadImg(imgFile,event)
//			},
//			function(error) {
//				alert("error")
//			});
//	}
//	$(".camera").click(function() { //点击图标调用查询相册图片
//		chooseImg()
//	})
	var imgDatas = "";
	  $(function () {  
	   var   imgUrl=null ;   // 图片相对地址
       var   flag;      //判断是新增还是修改
       var   url;       //请求地址
       var imgCt = 0;
       var btn = $("#selImg");  
       btn.uploadFile({  
           fileSuffixs: ["jpg", "png","jpeg","JPG", "PNG","JPEG"],  
           buttonFeature: true,  
           errorText: "{0}",  
           maximumFilesUpload: 3,//最大文件上传数  
          //dataType:'json',
           onComplete: function (url) {  
         
           }, 
           onChosen: function (file, obj) {  
        	   imgCt++;
               if(imgCt==3){
            	   //隐藏
//          	   $(".cz-inputpic").hide();
               }             
           }, 
           //点击提交时压缩图片
           onSubmitHandle: function (uploadFileNumber) {
        	   var quality=50;
        	   var j=1;
        	   var imgData="";
        	   //只允许上传3张图片
        	   for(var i=1;i<=3;i++){
        		   var img = document.getElementById("img"+i);
        		   if(img != null){
        			   //调用插件压缩图片
        			   var imgDat=jic.compress(img,quality).src;
        			   imgData = imgData+"img"+j+".jpg:"+imgDat.substring(imgDat.lastIndexOf(",")+1)+";";
        			   j++;
        		   }
        	   }
        	   $("#imgData").val(imgData);
        	   return true;
        	   
           },
           perviewImageElementId: "fileList", //设置预览图片的元素id  
           perviewImgStyle: { width: '10px', height: '10px', border: '1px solid #ebebeb' }//设置预览图片的样式  
       });  

        upload = btn.data("uploadFileData"); 
		
   });
	$(".login_btn").click(function() { //点击提交
		var Star = star[star.length - 1] //获取星级数
		if(Star == undefined) {
			Star = 5
		}
		var Content = document.getElementById("textareabox").value //获取评论内容
		var filename = {
			
		}
		var img = document.querySelectorAll("#img0")
//		for(var i=0;i<img.length;i++){
//				var imgs = img[i].src.split(",") [1]		
//				filename  +=""+i+":"+imgs+";"
			if(img.length==1){
				filename = {
					filename1:"data:image/png;base64,"+img[0].src.split(",") [1]
				}
			}
			if(img.length==2){
				filename = {
					filename1:"data:image/png;base64,"+img[0].src.split(",") [1],
					filename2:"data:image/png;base64,"+img[1].src.split(",") [1],
				}
			}
			if(img.length==3){
				filename = {
					filename1:"data:image/png;base64,"+img[0].src.split(",") [1],
					filename2:"data:image/png;base64,"+img[1].src.split(",") [1],
					filename3:"data:image/png;base64,"+img[2].src.split(",") [1],
				}
			}
//			console.log(filename)
//			}
//		console.log(angular.toJson(filename))
		$http({
				method: 'post',
				url: '' + $rootScope.Location + 'Comment/comment_road',
				headers: {
					'Content-Type': 'application/x-www-form-urlencoded'
				},
				data: {
					user_Id: localStorage.getItem("user_ID"),
					token: localStorage.getItem("token"),
					order_Id: $stateParams.Id,
					star: Star,
					road_Id:$stateParams.id,
					content: Content,
					type: $stateParams.type,    //订单里的评论
					types:$stateParams.types,    //第几次评论
					fileData:angular.toJson(filename)
				}
			}).success(function(data) {
				console.log(data)
				if(data["status"]==1 && $stateParams.type==1){
					$(".addressdialog").show();
					$(".addressdialog").html(data["message"]);
					$(".addressdialog").fadeOut(1200);
					setTimeout(function(){
						$state.go("main.wait_comment")
					},1000)					
				}else{
					if(data["status"]==1 && $stateParams.type==2){
					$(".addressdialog").show();
					$(".addressdialog").html(data["message"]);
					$(".addressdialog").fadeOut(1200);
					setTimeout(function(){
						$state.go("main.routecommentlist",{
							Id:$stateParams.id
						})
					},1000)		
					}else{
						$(".addressdialog").show();
						$(".addressdialog").html(data["message"]);
						$(".addressdialog").fadeOut(1200);
					}
				}	
			})
	})	
//		if($(".ul_img li").length <= 0) { //若不选取图片，则直接提交
//			$http({
//				method: 'post',
//				url: '' + $rootScope.Location + 'Comment/comment_road',
//				headers: {
//					'Content-Type': 'application/x-www-form-urlencoded'
//				},
//				data: {
//					user_Id: localStorage.getItem("user_ID"),
//					token: localStorage.getItem("token"),
//					order_Id: $stateParams.Id,
//					star: Star,
//					content: Content,
//					type: 1
//				}
//			}).success(function(data) {
//				console.log(data)
//			})
//		} else {
//			var urlImg = localStorage.getItem("urlImg").split(",")
//			pickFile(urlImg, Star, Content)
//		}
//	})

//	function pickFile(paths, star, content) {
//		var task = null;
//		task = plus.uploader.createUpload(
//			"http://demo.tl178.cn/Comment/comment_road", {
//				method: "POST"
//			},
//			function(t, status) {
//				plus.nativeUI.showWaiting("上传中...");
//				if(status == 200) {
//					//模拟上传完之后
//					plus.nativeUI.closeWaiting();
//					alert("上传成功: " + t.responseText);
//				} else {
//					plus.nativeUI.closeWaiting();
//					alert("上传失败" + status);
//				}
//			}
//		);
//		for(var i in paths) {
//			task.addFile(paths[i], 
//			{   
//				key:'uper' + i, 
//				'name': paths[i].substr(paths[i].lastIndexOf('/'))
//			}
//			);
//			task.addData("token", localStorage.getItem("token"))
//			task.addData("user_Id", localStorage.getItem("user_ID"))
//			task.addData("order_Id", $stateParams.Id)
//			task.addData("star", star.toString())
//			task.addData("content", content.toString())
//			task.addData("type", "1") 
//		}  
//		task.start(); 
//	}
}])